
// 新增用户
function addUser(obj) {
	if(UTIL.checkButton(obj)) {
		// 获取参数
		var realName = $("#addUserRealName").val();
		if(!realName) {
			alert("姓名不能为空");
			UTIL.releaseButton(obj);
			return false;
		}
		var userName = $("#addUserUserName").val();
		if(!userName) {
			alert("用户名不能为空");
			UTIL.releaseButton(obj);
			return false;
		}
		
		// 调用接口
		var data = {
			realName: realName,
			userName: userName
		};
		API.managementAddUser(data, function(res) {
			if (res.code == '0') {
				window.location.href = "/management/user_manage_list.htm?status=1";
			} else {
				alert(res.desc);
			}
		});
		UTIL.releaseButton(obj);
		return false;
	}
}

// 选择权限后直接调用接口修改
function setRole(obj, id) {
	
	var role = $(obj).val();
	
	var data = {
		id: id,
		role: role
	};
	
	API.managementSetRole(data, function(res) {
		if(res.code == '0') {
			var selectOption = res.data.retCode;
			var options = selectOption.split(",");
			var select = $(obj).parent().next("td").children();
			select.empty();
			select.append("<option value=''>无</option>");
			if(selectOption){
				for(var i=0;i<options.length;i++){
					var tab = options[i].split("|");
					select.append("<option value='"+tab[1]+"'>"+tab[0]+"</option>");
				}
			}
			
			var outsourceFlag = res.data.outsourceFlag;
			var outsourceDisplay = "否";
			if(outsourceFlag == '1') {
				outsourceDisplay = "是";
			}
			$(obj).parent().next(".outsourceFlag").html(outsourceDisplay);
		} else {
			alert(res.desc);
		}
	});
}
//选择权限后直接调用接口修改
function setPage(obj, id) {
	
	var tabId = $(obj).val();
	
	var data = {
		'id': id,
		'tabId': tabId
	};
	
	API.managementSetPage(data, function(res) {
		if(res.code == '0') {
		} else {
			alert(res.desc);
		}
	});
}
//选择权限后直接调用接口修改
function setCompany(obj, id) {
	
	var companyId = $(obj).val();
	
	var data = {
		"id": id,
		"companyId": companyId
	};
	
	API.managementSetCompany(data, function(res) {
		if(res.code == '0') {
		} else {
			alert(res.desc);
		}
	});
}
// 隐藏用户
function hideUser(obj, id) {
	if(UTIL.checkButton(obj)) {
		var data = {
			id: id
		};
		
		API.managementHideUser(data, function(res) {
			if(res.code == '0') {
				window.location.reload();
			} else {
				alert(res.desc);
				window.location.reload();
			}
		});
		UTIL.releaseButton(obj);
		return false;
	}
}

// 展现用户
function displayUser(obj, id) {
	if(UTIL.checkButton(obj)) {
		var data = {
			id: id
		};
		
		API.managementDisplayUser(data, function(res) {
			if(res.code == '0') {
				window.location.reload();
			} else {
				alert(res.desc);
			}
		});
		UTIL.releaseButton(obj);
		return false;
	}
}
